package com.message.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.message.VO.SampleInfoDTO;
import com.message.VO.SampleInfoUpdateVo;
import com.message.VO.SampleInfoVO;
import com.message.dao.*;
import com.message.pojo.*;
import com.message.service.SampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName : SampleServiceImpl  //类名
 * @Description :   //描述
 * @Author : yangqi  //作者
 * @Date: 2021-02-26 10:46  //创建时间
 * @modifier: //修改人
 * @modificationTime: //修改时间
 */
@Service
public class SampleServiceImpl implements SampleService {
    @Autowired
    private SampleInfoMapper sampleInfoMapper;
    @Autowired
    private SampleToxinInfoMapper sampleToxinInfoMapper;
    @Autowired
    private CropSpeciesMapper cropSpeciesMapper;
    @Autowired
    private AddressProvinceMapper addressProvinceMapper;
    @Autowired
    private AddressCityMapper addressCityMapper;
    @Autowired
    private AddressTownMapper addressTownMapper;
    @Autowired
    private SampleToxinMapper sampleToxinMapper;
    @Autowired
    private CropCategoryMapper cropCategoryMapper;
    @Autowired
    private BacterialStrainInfoMapper bacterialStrainInfoMapper;
    @Override
    public PageInfo<SampleInfoVO> findAll(SampleInfoDTO sampleInfoDTO,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SampleInfoVO> list = sampleInfoMapper.selectAll(sampleInfoDTO);
        PageInfo<SampleInfoVO> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<SampleToxinInfo> findAllToxinInfo() {
        return sampleToxinInfoMapper.selectAll();
    }

    @Override
    public List<CropSpecies> findAllCropSpecies() {
        return cropSpeciesMapper.selectAll();
    }

    @Override
    public List<AddressProvince> findAllProvice() {
        return addressProvinceMapper.selectAll();
    }

    @Override
    public List<AddressCity> findCityByProvice(String code) {
        return addressCityMapper.selectByCode(code);
    }

    @Override
    public List<AddressTown> findCountyByCity(String code) {
        return addressTownMapper.selectByCode(code);
    }

    @Override
    public List<SampleInfoVO> findAll() {
        return sampleInfoMapper.selectAllExcel();
    }

    @Override
    public List<SampleInfoVO> findByIdList(Integer[] idList) {
        return sampleInfoMapper.selectByIdList(idList);
    }

    @Override
    public int addSampleInfo(SampleInfo sampleInfo) {
        return sampleInfoMapper.insert(sampleInfo);
    }

    @Override
    public int addSampleToxins(SampleToxin[] sampleToxins) {
        return sampleToxinMapper.insertByList(sampleToxins);
    }

    @Override
    public CropCategory findCropCategory(String cropCategory) {
        return cropCategoryMapper.selectById(cropCategory);
    }

    @Override
    public int deleteByIdList(Integer[] idList) {
        return sampleInfoMapper.deleteByIdList(idList);
    }

    @Override
    public List<CropCategory> findAllCropCategory() {
        return cropCategoryMapper.selectAll();
    }

    @Override
    public int addBacterialStrainInfo(BacterialStrainInfo[] bacterialStrainInfos) {
        return bacterialStrainInfoMapper.inserts(bacterialStrainInfos);
    }

    @Override
    public SampleInfoUpdateVo findById(Integer id) {
        return sampleInfoMapper.selectById(id);
    }

    @Override
    public List<BacterialStrainInfo> selectBacterialStrainInfo(Integer sampleId) {
        return bacterialStrainInfoMapper.selectBacterialStrainInfo(sampleId);
    }

    @Override
    public int updateSampleInfo(SampleInfo sampleInfo) {
        return sampleInfoMapper.updateByPrimaryKeySelective(sampleInfo);
    }

    @Override
    public int deleteToxinByPrimaryKey(Integer id) {
        return sampleToxinMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertBacterialStrainInfoByList(BacterialStrainInfo[] record) {
        return bacterialStrainInfoMapper.insertBacterialStrainInfoByList(record);
    }

    @Override
    public int deleteBacterialStrainInfoByPrimaryKey(Integer id) {
        return bacterialStrainInfoMapper.deleteByPrimaryKey(id);
    }
}
